﻿using blackhouse.WebNemo.Business.Groups;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace blackhouse.WebNemo.Business.Extensionable {
    public abstract class RecordExtension {

        #region Fields

        private GroupRecord record;

        #endregion

        #region Constructors

        public RecordExtension(GroupRecord record) {
            this.record = record;
        }

        #endregion

        #region Methods

        public string GetIdentyficator() {
            return this.GetIdentyficator(this.record);
        }

        protected abstract string GetIdentyficator(GroupRecord record);

        public void RecordChanged(RecordChangeType type) {
            this.RecordChanged(record, type);
        }

        protected abstract void RecordChanged(GroupRecord record, RecordChangeType type);

        protected void SaveRecord() {
            this.record.Save(false);
        }

        public bool RecordIsValid() {
            string v = String.Empty;
            return this.RecordIsValid(out v);
        }

        public virtual bool RecordIsValid(out string notValidMessage) {
            notValidMessage = "";
            return true;
        }

        public virtual bool ShowOnRecordsList(GroupRecord record) {
            return true;
        }

        public virtual bool ShowOnReferencesRecordsList(GroupRecord record, GroupColumn parentColumn) {
            return true;
        }

        #endregion

        #region NULL

        private static RecordExtension nulle = new NULLRecordExtension();

        public static RecordExtension NULL {
            get { return nulle; }
        }

        private class NULLRecordExtension : RecordExtension {

            public NULLRecordExtension() : base(null) { }

            protected override string GetIdentyficator(GroupRecord record) {
                return "";
            }

            protected override void RecordChanged(GroupRecord record, RecordChangeType type) { }

        }

        #endregion

    }

}
